import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

public class TestTx {

    /*redis的事务不会主动回滚  必须手动回滚 multi.discard(); 取消事务 */
    public static void main(String[] args) {
        Jedis jedis=new Jedis("127.0.0.1",6379);
        Transaction multi=jedis.multi();//开启redis事务
        try {
            //设置数据
            multi.set("ka", "va");
            multi.set("kb", "vb");
            int num=1/0;
            multi.set("kc", "vc");
        } catch (Exception e) {
            //multi.discard();
            e.printStackTrace();
        }
        //redis事务提交
        multi.exec();
    }
}
